package com.yami.shop.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yami.shop.bean.enums.UserFundDetailEnum;
import com.yami.shop.bean.model.User;
import com.yami.shop.bean.model.UserCashOut;
import com.yami.shop.bean.model.UserFundDetail;
import com.yami.shop.bean.param.UserCashOutApprovalParam;
import com.yami.shop.bean.param.UserCashOutBatchApprovalParam;
import com.yami.shop.bean.vo.UserCashOutVo;
import com.yami.shop.bean.vo.UserFundDetailVo;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.payment.WeChatPayment;
import com.yami.shop.payment.dto.GetJsapiServiceDto;
import com.yami.shop.payment.dto.TransferAccountsDto;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.UserCashOutService;
import com.yami.shop.service.UserFundDetailService;
import com.yami.shop.service.UserService;
import com.yami.shop.sys.model.SysConfig;
import com.yami.shop.sys.service.SysConfigService;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 会员提现表 前端控制器
 * </p>
 *
 * @author jcd
 * @since 2024-07-26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/cashOut")
public class UserCashOutController {
    private final UserCashOutService userCashOutService;

    @Autowired
    private UserService userService;

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private UserFundDetailService userFundDetailService;

    @Autowired
    private WeChatPayment weChatPayment;

    /**
     * 分页查询
     *
     * @param page        分页对象
     * @param userCashOut 用户地址管理
     * @return 分页数据
     */
    @PreAuthorize("@pms.hasPermission('user:cashOut:page')")
    @GetMapping("/page")
    public ServerResponseEntity<IPage<UserCashOut>> getUserAddrPage(PageParam page, UserCashOut userCashOut) {
        PageParam page1 = userCashOutService.page(page, new LambdaQueryWrapper<UserCashOut>());

        List<UserCashOut> records = page1.getRecords();

        List<UserCashOutVo> list1 = new ArrayList<>();
        for (UserCashOut detail : records) {
            UserCashOutVo vo = new UserCashOutVo();
            BeanUtil.copyProperties(detail, vo);

            User byId = userService.getById(detail.getUserAccountTableId());
            if (byId != null) {
                vo.setUserName(byId.getNickName());
            }
            list1.add(vo);
        }

        page1.setRecords(list1);
        return ServerResponseEntity.success(page1);
    }


    /**
     * 通过id查询用户地址管理
     *
     * @param id id
     * @return 单个数据
     */
    @PreAuthorize("@pms.hasPermission('user:cashOut:info')")
    @GetMapping("/info/{id}")
    public ServerResponseEntity<UserCashOut> getById(@PathVariable("id") Long id) {
        UserCashOut byId = userCashOutService.getById(id);
        UserCashOutVo vo = new UserCashOutVo();
        BeanUtil.copyProperties(byId, vo);
        User byId1 = userService.getById(byId.getUserAccountTableId());
        if (byId1 != null) {
            vo.setUserName(byId1.getNickName());
        }
        return ServerResponseEntity.success(vo);
    }

    /**
     * 新增用户地址管理
     *
     * @param userCashOut 用户地址管理
     * @return 是否新增成功
     */
    @SysLog("新增用户地址管理")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:cashOut:save')")
    @Transactional
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid UserCashOut userCashOut) {
        Long userId = SecurityUtils.getSysUser().getUserId();

        userCashOut.setCreateTime(new Date());
        userCashOut.setCreateBy(userId);
        userCashOut.setDelFlag(0);

        if(userCashOut.getState() == 0){
            //新增申请,扣除用户余额
            //个人所得税
            BigDecimal individualIncomeTax = BigDecimal.ZERO;

            if(StringUtils.equals(userCashOut.getUserType(),"leader")){
                if(userCashOut.getCashOutType() == 0){
                    //提现类型 0:团长提现时,满5000需要缴纳个人所得税
                    Map<String,Object> rmap1=userCashOutService.calculateIndividualIncomeTax(userCashOut.getUserAccountTableId(),userCashOut.getCashMoney().toPlainString());
                    BigDecimal individualIncomeTax1 = (BigDecimal)rmap1.get("individualIncomeTax");
                    if(individualIncomeTax1 == null){
                        return ServerResponseEntity.showFailMsg("个人所得税不能为空");
                    }
                    if(userCashOut.getIndividualIncomeTax().compareTo(individualIncomeTax1) != 0){
                        return ServerResponseEntity.showFailMsg("个人所得税不能修改");
                    }

                    individualIncomeTax = individualIncomeTax1;
                }else if(userCashOut.getCashOutType() == 1){
                    //需上传发票
                    //检查是否有发票未审核通过记录
                    Date date = new Date();
                    DateTime begin = DateUtil.beginOfMonth(date);
                    DateTime end = DateUtil.endOfMonth(date);

                    List<UserCashOut> list = userCashOutService.lambdaQuery()
                            .eq(UserCashOut::getUserAccountTable, "tz_user")
                            .eq(UserCashOut::getUserAccountTableField, "distribution_bonus")
                            .eq(UserCashOut::getUserAccountTableId, userCashOut.getUserAccountTableId())
                            .in(UserCashOut::getState, Arrays.asList(3,5))
                            .between(UserCashOut::getCreateTime,begin,end)
                            .list();
                    if(list.size() > 0){
                        return ServerResponseEntity.showFailMsg("本月存在未审核通过发票信息");
                    }
                }
            }

            BigDecimal cashMoney = userCashOut.getCashMoney();

            //提现金额加上个人所得税
            cashMoney= cashMoney.add(individualIncomeTax);


            User byId = userService.getById(userCashOut.getUserAccountTableId());
            if(byId == null){
                return ServerResponseEntity.showFailMsg("查询用户 不能为空");
            }

            BigDecimal distributionBonus = byId.getDistributionBonus();
            if(distributionBonus == null){
                return ServerResponseEntity.showFailMsg("查询用户余额为空");
            }

            if(distributionBonus.compareTo(cashMoney) < 0){
                return ServerResponseEntity.showFailMsg("本次提现金额 大于 用户余额");
            }

            //余额减本次提现金额
            BigDecimal subtract = distributionBonus.subtract(cashMoney);

            User user = new User();
            user.setUserId(byId.getUserId());
            user.setDistributionBonus(subtract);
            userService.updateById(user);


            UserFundDetail detail=new UserFundDetail();
            detail.setUserType("tz_user");
            detail.setUid(byId.getUserId());
            detail.setCategory(UserFundDetailEnum.DISTRIBUTION_BONUS.getValue());
            detail.setType(UserFundDetailEnum.TYPE_3.getValue());
            detail.setPm(Integer.valueOf(UserFundDetailEnum.PM_0.getValue()));
            detail.setMoney(cashMoney);
            detail.setResidueMoney(subtract);
            detail.setTitle("提现扣除");
            detail.setDetails("提现扣除:"+cashMoney +", 剩余:"+subtract);
            detail.setDelFlag(0);

            detail.setCreateBy(userId);
            detail.setCreateTime(new Date());

            detail.setOrderNumber(String.valueOf(userCashOut.getId()));

            userFundDetailService.save(detail);
        }

        boolean save = userCashOutService.save(userCashOut);
        return ServerResponseEntity.success(save);
    }

    /**
     * 修改用户地址管理
     *
     * @param userCashOut 用户地址管理
     * @return 是否修改成功
     */
    @SysLog("修改用户地址管理")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:cashOut:update')")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid UserCashOut userCashOut) {
        Long userId = SecurityUtils.getSysUser().getUserId();

        userCashOut.setUpdateBy(userId);
        userCashOut.setUpdateTime(new Date());

        return ServerResponseEntity.success(userCashOutService.updateById(userCashOut));
    }

    /**
     * 通过id删除用户地址管理
     *
     * @param id id
     * @return 是否删除成功
     */
    @SysLog("删除用户地址管理")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('user:cashOut:delete')")
    public ServerResponseEntity<Boolean> removeById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(userCashOutService.removeById(id));
    }

    /**
     * 提现审批
     *
     * @param param 用户地址管理
     * @return 是否新增成功
     */
    @SysLog("提现审批")
    @PostMapping("/approval")
    @PreAuthorize("@pms.hasPermission('user:cashOut:update')")
    @Transactional
    public ServerResponseEntity<Boolean> approval(@RequestBody @Valid UserCashOutApprovalParam param) {
        Long userId = SecurityUtils.getSysUser().getUserId();

        UserCashOut byId = userCashOutService.getById(param.getId());
        if (byId == null) {
            return ServerResponseEntity.showFailMsg("查询提现记录不存在");
        }

        if (byId.getState() != 0) {
            return ServerResponseEntity.showFailMsg("当前提现记录 不能重复审核");
        }

        if (StringUtils.equals(param.getResult(), "0")) {
            //通过
            //实际打款金额
            BigDecimal subtract = byId.getCashMoney().subtract(byId.getCommissionMoney());
            if (StringUtils.equals(byId.getType(), "WeChat")) {
                //微信提现,自动转账
                String payeeInfo = byId.getPayeeInfo();

                Gson gson = new Gson();
                Type mapType = new TypeToken<Map<String, String>>(){}.getType();
                Map<String, String> map = gson.fromJson(payeeInfo, mapType);

                String openId = map.get("openId");

                TransferAccountsDto dto=new TransferAccountsDto();
                dto.setTransferAmount(subtract);
                dto.setOpenid(openId);

                GetJsapiServiceDto getJsapiServiceDto = new GetJsapiServiceDto();
                getJsapiServiceDto.setWechatpayMchid(WeChatPayment.wechatpayMchid);
                getJsapiServiceDto.setWechatpayMchserialno(WeChatPayment.wechatpayMchserialno);
                getJsapiServiceDto.setWechatpayPrivatekey(WeChatPayment.wechatpayPrivatekey);
                getJsapiServiceDto.setWechatpayApiv3key(WeChatPayment.wechatpayApiv3key);

                getJsapiServiceDto.setWechatpayAppid(WeChatPayment.wechatpayAppid);
                getJsapiServiceDto.setWechatpayAppsecret(WeChatPayment.wechatpayAppsecret);


                weChatPayment.transferAccounts(dto,getJsapiServiceDto);
            } else if (StringUtils.equals(byId.getType(), "BankCard")) {
                //银行卡手动转账
            }

            /*UserCashOut out = new UserCashOut();
            out.setId(byId.getId());
            out.setState(1);//通过
            userCashOutService.updateById(out);*/

            //设置完成状态
            if(StringUtils.equals(byId.getUserType(),"leader")){
                if(byId.getCashOutType() == 0){
                    //提现完成
                    userCashOutService.lambdaUpdate().set(UserCashOut::getState,1).eq(UserCashOut::getId,byId.getId()).update();
                }else if(byId.getCashOutType() == 1){
                    //提现完成,等待上传发票
                    userCashOutService.lambdaUpdate().set(UserCashOut::getState,5).eq(UserCashOut::getId,byId.getId()).update();
                }
            }else if(StringUtils.equals(byId.getUserType(),"member")){
                userCashOutService.lambdaUpdate().set(UserCashOut::getState,1).eq(UserCashOut::getId,byId.getId()).update();
            }

        } else if (StringUtils.equals(param.getResult(), "1")) {
            //驳回
            if (StringUtils.isBlank(param.getRejectReason())) {
                return ServerResponseEntity.showFailMsg("驳回必须填写原因");
            }

            UserCashOut out = new UserCashOut();
            out.setId(byId.getId());

            out.setState(2);//驳回
            out.setRejectReason(param.getRejectReason());

            userCashOutService.updateById(out);


            User byId1 = userService.getById(byId.getUserAccountTableId());
            if(byId1 == null){
                throw new RuntimeException("查询用户 不能为空");
            }

            BigDecimal distributionBonus = byId1.getDistributionBonus();

            if( distributionBonus == null){
                distributionBonus = BigDecimal.ZERO;
            }

            BigDecimal add = distributionBonus.add(byId.getCashMoney()).add(byId.getIndividualIncomeTax());

            User user = new User();
            user.setUserId(byId1.getUserId());
            user.setDistributionBonus(add);
            userService.updateById(user);

            UserFundDetail detail=new UserFundDetail();
            detail.setUserType("tz_user");
            detail.setUid(byId1.getUserId());
            detail.setCategory(UserFundDetailEnum.DISTRIBUTION_BONUS.getValue());
            detail.setType(UserFundDetailEnum.TYPE_4.getValue());
            detail.setPm(Integer.valueOf(UserFundDetailEnum.PM_1.getValue()));
            detail.setMoney(byId.getCashMoney());
            detail.setResidueMoney(add);
            detail.setTitle("提现驳回,余额退回");
            detail.setDetails("余额退回:"+byId.getCashMoney() +", 剩余:"+add);
            detail.setDelFlag(0);

            detail.setCreateBy(userId);
            detail.setCreateTime(new Date());

            detail.setOrderNumber(String.valueOf(byId.getId()));

            userFundDetailService.save(detail);
        }

        return ServerResponseEntity.success(true);
    }

    /**
     * 查询提现手续费
     *
     * @param uid,cashMoney
     * @return
     */
    @PreAuthorize("@pms.hasPermission('user:cashOut:info')")
    @GetMapping("/getServiceCharge")
    public ServerResponseEntity<BigDecimal> getServiceCharge(String uid,String cashMoney) {
        if (StringUtils.isBlank(uid)) {
            return ServerResponseEntity.showFailMsg("uid 不能为空");
        }

        User byId = userService.getById(uid);
        if(byId == null){
            return ServerResponseEntity.showFailMsg("查询用户 不能为空");
        }

        if (StringUtils.isBlank(cashMoney)) {
            return ServerResponseEntity.showFailMsg("提现金额不能为空");
        }

        if (new BigDecimal(cashMoney).compareTo(BigDecimal.ZERO) <= 0) {
            return ServerResponseEntity.showFailMsg("提现金额不能 小于等于零");
        }

        BigDecimal distributionBonus = byId.getDistributionBonus();
        if(distributionBonus == null){
            return ServerResponseEntity.showFailMsg("查询用户余额为空");
        }

        if(distributionBonus.compareTo(new BigDecimal(cashMoney)) < 0){
            return ServerResponseEntity.showFailMsg("本次提现金额 大于 用户余额");
        }

        SysConfig user_cash_out_service_charge = sysConfigService.lambdaQuery().eq(SysConfig::getParamKey, "user_cash_out_service_charge").one();
        if(user_cash_out_service_charge == null){
            return ServerResponseEntity.showFailMsg("提现手续费未配置");
        }

        //本次手续费
        BigDecimal multiply = new BigDecimal(cashMoney).multiply(new BigDecimal(user_cash_out_service_charge.getParamValue()));

        return ServerResponseEntity.success(multiply);
    }

    @SysLog("批量提现审批")
    @PostMapping("/batchApproval")
    @PreAuthorize("@pms.hasPermission('user:cashOut:update')")
    @Transactional
    public ServerResponseEntity<Boolean> batchApproval(@RequestBody @Valid UserCashOutBatchApprovalParam param) {
        Long userId = SecurityUtils.getSysUser().getUserId();

        List<UserCashOut> list = userCashOutService.lambdaQuery().in(UserCashOut::getId, param.getIds()).list();
        if(list.isEmpty()){
            return ServerResponseEntity.showFailMsg("查询待批量审批记录为空");
        }

        List<UserCashOut> collect = list.stream().filter(o -> o.getState() != 0).collect(Collectors.toList());
        if(!collect.isEmpty()){
            return ServerResponseEntity.showFailMsg("待批量审批记录 包含已审批记录");
        }

        List<String> collect1 = list.stream().map(o -> o.getType()).distinct().collect(Collectors.toList());
        if(collect1.size() > 1){
            return ServerResponseEntity.showFailMsg("待批量审批记录 只能为同一种提现方式,才能批量审批");
        }


        if (StringUtils.equals(param.getResult(), "0")) {
            //通过
            //本批次提现方式
            String s = collect1.get(0);
            if (StringUtils.equals( s, "WeChat")) {
                //微信提现,自动转账
                GetJsapiServiceDto getJsapiServiceDto = new GetJsapiServiceDto();
                getJsapiServiceDto.setWechatpayMchid(WeChatPayment.wechatpayMchid);
                getJsapiServiceDto.setWechatpayMchserialno(WeChatPayment.wechatpayMchserialno);
                getJsapiServiceDto.setWechatpayPrivatekey(WeChatPayment.wechatpayPrivatekey);
                getJsapiServiceDto.setWechatpayApiv3key(WeChatPayment.wechatpayApiv3key);

                getJsapiServiceDto.setWechatpayAppid(WeChatPayment.wechatpayAppid);
                getJsapiServiceDto.setWechatpayAppsecret(WeChatPayment.wechatpayAppsecret);

                List<TransferAccountsDto> list1=new ArrayList<>();
                for(UserCashOut out:list){
                    //实际打款金额
                    BigDecimal subtract = out.getCashMoney().subtract(out.getCommissionMoney());

                    String payeeInfo = out.getPayeeInfo();

                    Gson gson = new Gson();
                    Type mapType = new TypeToken<Map<String, String>>(){}.getType();
                    Map<String, String> map = gson.fromJson(payeeInfo, mapType);

                    String openId = map.get("openId");

                    TransferAccountsDto dto=new TransferAccountsDto();
                    dto.setTransferAmount(subtract);
                    dto.setOpenid(openId);

                    list1.add(dto);
                }
                weChatPayment.transferAccountsBatch(list1,getJsapiServiceDto);
            }else if (StringUtils.equals( s, "BankCard")) {
                //银行卡手动转账
            }

            //设置完成状态
            for(UserCashOut out:list){
                if(StringUtils.equals(out.getUserType(),"leader")){
                    if(out.getCashOutType() == 0){
                        //提现完成
                        userCashOutService.lambdaUpdate().set(UserCashOut::getState,1).eq(UserCashOut::getId,out.getId()).update();
                    }else if(out.getCashOutType() == 1){
                        //提现完成,等待上传发票
                        userCashOutService.lambdaUpdate().set(UserCashOut::getState,5).eq(UserCashOut::getId,out.getId()).update();
                    }
                }else if(StringUtils.equals(out.getUserType(),"member")){
                    userCashOutService.lambdaUpdate().set(UserCashOut::getState,1).eq(UserCashOut::getId,out.getId()).update();
                }
            }
        } else if (StringUtils.equals(param.getResult(), "1")) {
            //驳回
            if (StringUtils.isBlank(param.getRejectReason())) {
                return ServerResponseEntity.showFailMsg("驳回必须填写原因");
            }

            userCashOutService.lambdaUpdate().set(UserCashOut::getState,2)
                    .set(UserCashOut::getRejectReason,param.getRejectReason())
                    .in(UserCashOut::getId,param.getIds()).update();


            for(UserCashOut out:list){
                User byId1 = userService.getById(out.getUserAccountTableId());
                if(byId1 == null){
                    throw new RuntimeException("查询用户 不能为空");
                }

                BigDecimal distributionBonus = byId1.getDistributionBonus();

                if( distributionBonus == null){
                    distributionBonus = BigDecimal.ZERO;
                }

                BigDecimal add = distributionBonus.add(out.getCashMoney()).add(out.getIndividualIncomeTax());

                User user = new User();
                user.setUserId(byId1.getUserId());
                user.setDistributionBonus(add);
                userService.updateById(user);

                UserFundDetail detail=new UserFundDetail();
                detail.setUserType("tz_user");
                detail.setUid(byId1.getUserId());
                detail.setCategory(UserFundDetailEnum.DISTRIBUTION_BONUS.getValue());
                detail.setType(UserFundDetailEnum.TYPE_4.getValue());
                detail.setPm(Integer.valueOf(UserFundDetailEnum.PM_1.getValue()));
                detail.setMoney(out.getCashMoney());
                detail.setResidueMoney(add);
                detail.setTitle("提现驳回,余额退回");
                detail.setDetails("余额退回:"+out.getCashMoney() +", 剩余:"+add);
                detail.setDelFlag(0);

                detail.setCreateBy(userId);
                detail.setCreateTime(new Date());

                userFundDetailService.save(detail);
            }
        }
        return ServerResponseEntity.success(true);
    }

    /**
     * 计算个人所得税
     * @param uid
     * @return
     */
    @PreAuthorize("@pms.hasPermission('user:cashOut:info')")
    @GetMapping("/calculateIndividualIncomeTax")
    public ServerResponseEntity<Map<String,Object>> calculateIndividualIncomeTax(String uid,String cashOutMoney) {
        if(StringUtils.isBlank(uid)){
            return ServerResponseEntity.showFailMsg("uid 不能为空");
        }

        if(StringUtils.isBlank(cashOutMoney)){
            return ServerResponseEntity.showFailMsg("cashOutMoney 不能为空");
        }

        BigDecimal bigDecimal1 = new BigDecimal(cashOutMoney);
        if(bigDecimal1.compareTo(BigDecimal.ZERO) <= 0){
            return ServerResponseEntity.showFailMsg("提现金额不能为 0或负数");
        }

        Map<String,Object> rmap1=userCashOutService.calculateIndividualIncomeTax(uid,cashOutMoney);
        return ServerResponseEntity.success(rmap1);
    }

    /**
     * 获取用户的营业执照历史,本次提现申请选择一个就可以了,不用重复上传
     * @param uid
     * @return
     */
    @PreAuthorize("@pms.hasPermission('user:cashOut:info')")
    @GetMapping("/getBusinessLicenseByCashOutHistory")
    public ServerResponseEntity<List<Map<String,String>>> getBusinessLicenseByCashOutHistory(String uid) {
        if(StringUtils.isBlank(uid)){
            return ServerResponseEntity.showFailMsg("uid 不能为空");
        }

        List<UserCashOut> list = userCashOutService.lambdaQuery()
                .eq(UserCashOut::getUserAccountTable, "tz_user")
                .eq(UserCashOut::getUserAccountTableField, "distribution_bonus")
                .eq(UserCashOut::getUserAccountTableId, uid)
                .in(UserCashOut::getState, Arrays.asList(1, 3, 4,5))
                .orderByDesc(UserCashOut::getCreateTime)
                .list();
        Gson gson=new Gson();
        List<Map<String,String>> list1=new ArrayList<>();
        for(UserCashOut out:list){
            List<String> businessLicense = list1.stream().map(m -> m.get("businessLicense")).collect(Collectors.toList());
            if(!businessLicense.contains(out.getBusinessLicenseJson())){
                Map map = gson.fromJson(out.getPayeeInfo(), Map.class);

                Map<String,String> map1=new HashMap<>();
                map1.put("name",(String)map.get("name")+"--"+(String)map.get("account"));
                map1.put("businessLicense",out.getBusinessLicenseJson());
                list1.add(map1);
            }
        }
        return ServerResponseEntity.success(list1);
    }


    @SysLog("发票审批")
    @PostMapping("/invoiceExamine")
    @PreAuthorize("@pms.hasPermission('user:cashOut:update')")
    @Transactional
    public ServerResponseEntity<Boolean> invoiceExamine(@RequestBody @Valid UserCashOutApprovalParam param) {
        Long userId = SecurityUtils.getSysUser().getUserId();

        UserCashOut byId = userCashOutService.getById(param.getId());
        if (byId == null) {
            return ServerResponseEntity.showFailMsg("查询提现记录不存在");
        }

        if (byId.getState() != 3) {
            return ServerResponseEntity.showFailMsg("当前提现记录 不能重复审核");
        }

        if (StringUtils.equals(param.getResult(), "0")) {
            //通过
            userCashOutService.lambdaUpdate().set(UserCashOut::getState,4).eq(UserCashOut::getId,byId.getId()).update();
        } else if (StringUtils.equals(param.getResult(), "1")) {
            //驳回
            if (StringUtils.isBlank(param.getRejectReason())) {
                return ServerResponseEntity.showFailMsg("驳回必须填写原因");
            }

            UserCashOut out = new UserCashOut();
            out.setId(byId.getId());
            out.setState(5);//重新上传发票
            out.setInvoiceRejectReason(param.getRejectReason());
            userCashOutService.updateById(out);

        }

        return ServerResponseEntity.success(true);
    }
}

